﻿using Services.Initial.PublicProject.PublicClass.ExtensionException;

namespace Services.Identity.Domain.Entities;

public class UserMessage
{
    public long MessageId { get; private set; }
    public long ActivityId { get; private set; }
    public List<UnsentUser> UnsentUsers { get; private set; } = [];
    public string Message { get; private set; }
    public DateTime CreateTime { get; private set; }
    private UserMessage() { }
    public static UserMessage Create(long activityId, string message)
    {
        if (string.IsNullOrEmpty(message))
        {
            throw new ExceptionWithStatus(System.Net.HttpStatusCode.BadRequest, "发送的消息不能为空");
        }
        var newMessage = new UserMessage()
        {
            ActivityId = activityId,
            Message = message,
            CreateTime = DateTime.Now            
        };
        return newMessage;
    }
    public void SetUnsentUsers(List<UnsentUser> users)
    {
        this.UnsentUsers.AddRange(users);
    }
}
